/*    */ package com.behavior.expression;
/*    */ 
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ import java.util.Stack;
/*    */ 
/*    */ public class Context
/*    */ {
/* 13 */   private Map<Expression, Integer> map = new HashMap<Expression, Integer>();
/*    */ 
/*    */   public void add(Expression s, Integer value) {
/* 16 */     this.map.put(s, value);
/*    */   }
/*    */   public Integer lookup(Expression s) {
/* 19 */     return (Integer)this.map.get(s);
/*    */   }
/*    */ 
/*    */   public static Expression build(String str)
/*    */   {
/* 24 */     Stack objects = new Stack();
/* 25 */     for (int i = 0; i < str.length(); i++) {
/* 26 */       char c = str.charAt(i);
/*    */ 
/* 28 */       if (c == '+')
/*    */       {
/* 31 */         Expression pop = (Expression)objects.pop();
/*    */ 
/* 34 */         objects.push(new PlusOperation(pop, new TerminalExpression(String.valueOf(str.charAt(++i)))));
/* 35 */       } else if (c == '-')
/*    */       {
/* 37 */         Expression pop = (Expression)objects.pop();
/*    */ 
/* 39 */         objects.push(new MinusOperation(pop, new TerminalExpression(String.valueOf(str.charAt(++i)))));
/*    */       }
/*    */       else
/*    */       {
/* 43 */         objects.push(new TerminalExpression(String.valueOf(str.charAt(i))));
/*    */       }
/*    */     }
/*    */ 
/* 47 */     return (Expression)objects.pop();
/*    */   }
/*    */ }